Skip to content

[WEB-6816]chore: added support for pql filters#39

Open
sangeethailango wants to merge 5 commits intomainfrom
chore-pql-support
Open

[WEB-6816]chore: added support for pql filters#39
sangeethailango wants to merge 5 commits intomainfrom
chore-pql-support

Conversation

@sangeethailango
Copy link
Copy Markdown
Member

@sangeethailango sangeethailango commented Apr 8, 2026

This pull request adds support for filtering work items using PQL (Project Query Language) in the work items API. The main changes introduce a new pql parameter to the work item listing functionality and include a corresponding unit test to ensure the filter works as expected.

API Enhancements:

  • Added an optional pql parameter to the ListWorkItemsParams interface in src/models/WorkItem.ts, enabling clients to filter work items using PQL queries.

Testing Improvements:

  • Added a unit test in work-items.test.ts to verify that the pql filter returns only work items matching the specified criteria.

Summary by CodeRabbit

  • New Features

    • Added an optional PQL query filter when listing work items for more granular results.
  • Tests

    • Added a unit test confirming PQL-based listing returns only matching work items and that created items are cleaned up.
  • Chores

    • Bumped package version to 0.2.10.

@sangeethailango sangeethailango requested a review from Copilot April 8, 2026 12:20
@makeplane
Copy link
Copy Markdown

makeplane bot commented Apr 8, 2026

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds SDK support for filtering work item listings via PQL by extending the list params type and introducing a unit test to validate the behavior.

Changes:

  • Added optional pql to ListWorkItemsParams for workItems.list(...) query filtering.
  • Added a unit test that exercises listing work items with a PQL filter.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/models/WorkItem.ts Extends list params typing to include pql for PQL-based filtering.
tests/unit/work-items/work-items.test.ts Adds a test case for pql filtering when listing work items.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +86 to +91
const allWorkItems = await client.workItems.list(workspaceSlug, projectId);
const priority = allWorkItems.results[0]?.priority ?? "none";

const filtered = await client.workItems.list(workspaceSlug, projectId, {
pql: `priority IN ("${priority}")`,
});
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can produce false positives: if the first listed work item has no priority (or a value not supported by PQL), the fallback to "none" can yield an empty filtered result set, and the assertions still pass because the loop doesn’t run. Consider making the test deterministic by setting a known priority on the created workItem (or selecting a work item with a defined priority) and building the PQL from that known value.

Copilot uses AI. Check for mistakes.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

Adds an optional pql?: string to ListWorkItemsParams in the WorkItem model and a unit test that verifies listing work items with a PQL filter for high-priority items. Also bumps package version to 0.2.10.

Changes

Cohort / File(s) Summary
Model Enhancement
src/models/WorkItem.ts
Added optional pql?: string to the exported ListWorkItemsParams interface to support PQL filtering when listing work items.
Test Coverage
tests/unit/work-items/work-items.test.ts
Added a unit test that creates a high-priority work item, lists with pql: 'priority IN ("high")', asserts results include the created item and all returned items have priority "high", and attempts cleanup in finally.
Version Bump
package.json
Updated package version from 0.2.9 to 0.2.10.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I hop through lines, a tiny PQL seed,
A high-priority whisper to help find the deed,
Test plants a carrot, then checks what it found,
Filters and fetches — the results all bound 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding PQL filter support to the work items API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore-pql-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/models/WorkItem.ts`:
- Around line 51-52: The file has Prettier formatting violations around the
expanded mapped type for WorkItem (the line referencing WorkItemExpandableFields
and the mapped type for Expanded/WorkItem); run your formatter (prettier) to
reformat src/models/WorkItem.ts and fix spacing/semicolons so the mapped type
line for [K in Expanded]: K extends keyof WorkItemExpandableFields ?
WorkItemExpandableFields[K] : never; matches project style, then commit the
formatted file.

In `@tests/unit/work-items/work-items.test.ts`:
- Around line 93-97: The test currently can pass vacuously when filtered.results
is empty; after verifying filtered and that filtered.results is an array, add an
assertion that filtered.results.length is greater than 0 to ensure at least one
item is returned, then continue the existing loop asserting each wi.priority
equals the expected priority (references: filtered, filtered.results, priority).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c665f4e4-0733-4ab0-9de4-41538a4a4f3b

📥 Commits

Reviewing files that changed from the base of the PR and between ebeb2f8 and e9af1db.

📒 Files selected for processing (2)
  • src/models/WorkItem.ts
  • tests/unit/work-items/work-items.test.ts

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/unit/work-items/work-items.test.ts (1)

85-105: Ensure created test data is always cleaned up (Line 104).

If any assertion fails before Line 104, pqlWorkItem is not deleted. Wrap assertions in try/finally so cleanup always runs.

Proposed refactor
   it("should list work items with pql filter", async () => {
     const name = randomizeName();
     const pqlWorkItem = await client.workItems.create(workspaceSlug, projectId, {
       name,
       priority: "high",
     });

-    const filtered = await client.workItems.list(workspaceSlug, projectId, {
-      pql: 'priority IN ("high")',
-    });
-
-    expect(filtered).toBeDefined();
-    expect(Array.isArray(filtered.results)).toBe(true);
-    expect(filtered.results.length).toBeGreaterThan(0);
-    expect(filtered.results.find((wi) => wi.id === pqlWorkItem.id)).toBeDefined();
-    for (const wi of filtered.results) {
-      expect(wi.priority).toBe("high");
-    }
-
-    await client.workItems.delete(workspaceSlug, projectId, pqlWorkItem.id!);
+    try {
+      const filtered = await client.workItems.list(workspaceSlug, projectId, {
+        pql: 'priority IN ("high")',
+      });
+
+      expect(filtered).toBeDefined();
+      expect(Array.isArray(filtered.results)).toBe(true);
+      expect(filtered.results.length).toBeGreaterThan(0);
+      expect(filtered.results.find((wi) => wi.id === pqlWorkItem.id)).toBeDefined();
+      for (const wi of filtered.results) {
+        expect(wi.priority).toBe("high");
+      }
+    } finally {
+      await client.workItems.delete(workspaceSlug, projectId, pqlWorkItem.id!);
+    }
   });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/work-items/work-items.test.ts` around lines 85 - 105, The test
"should list work items with pql filter" creates pqlWorkItem via
client.workItems.create but deletes it only at the end, so if an assertion
throws the created item may leak; wrap the assertions (the body between creation
and deletion) in a try/finally and perform
client.workItems.delete(workspaceSlug, projectId, pqlWorkItem.id!) in the
finally block, guarding the delete with a check that pqlWorkItem and
pqlWorkItem.id are defined to avoid runtime errors; this ensures cleanup even if
any expect calls fail.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/unit/work-items/work-items.test.ts`:
- Around line 85-105: The test "should list work items with pql filter" creates
pqlWorkItem via client.workItems.create but deletes it only at the end, so if an
assertion throws the created item may leak; wrap the assertions (the body
between creation and deletion) in a try/finally and perform
client.workItems.delete(workspaceSlug, projectId, pqlWorkItem.id!) in the
finally block, guarding the delete with a check that pqlWorkItem and
pqlWorkItem.id are defined to avoid runtime errors; this ensures cleanup even if
any expect calls fail.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6900ada8-f485-43a9-8052-4e6f7765fadd

📥 Commits

Reviewing files that changed from the base of the PR and between e9af1db and efa06f2.

📒 Files selected for processing (2)
  • src/models/WorkItem.ts
  • tests/unit/work-items/work-items.test.ts
✅ Files skipped from review due to trivial changes (1)
  • src/models/WorkItem.ts

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/work-items/work-items.test.ts`:
- Around line 95-103: The PQL test is non-deterministic because 'priority IN
("high")' can return many items across pages; change the call to
client.workItems.list (used with workspaceSlug, projectId) to either include a
PQL clause that uniquely identifies the created test item (e.g., add name or id:
`priority IN ("high") AND name = "..."` or use the test-created identifier
stored in pqlWorkItem) or set explicit pagination/sorting so the created item is
guaranteed to appear (e.g., request a sufficiently large page size and sort by
created/updated timestamp descending). Update the test assertions to use that
tightened PQL or pagination to reliably find pqlWorkItem in filtered.results.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: af10a7d3-30de-4928-9363-5a002b3489c5

📥 Commits

Reviewing files that changed from the base of the PR and between efa06f2 and 1e9d951.

📒 Files selected for processing (2)
  • package.json
  • tests/unit/work-items/work-items.test.ts
✅ Files skipped from review due to trivial changes (1)
  • package.json

Comment on lines +95 to +103
const filtered = await client.workItems.list(workspaceSlug, projectId, {
pql: 'priority IN ("high")',
});

expect(filtered).toBeDefined();
expect(Array.isArray(filtered.results)).toBe(true);
expect(filtered.results.length).toBeGreaterThan(0);
expect(filtered.results.find((wi) => wi.id === pqlWorkItem!.id)).toBeDefined();
for (const wi of filtered.results) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Make the PQL assertion deterministic to avoid pagination-related flakiness.

The filter priority IN ("high") is broad, so on busy projects your created item may not be in the returned page even when PQL works, causing intermittent failures (Line 95–103). Narrow the query to the created entity (e.g., include name/identifier in PQL) or set explicit pagination/sorting to ensure the created item is in-scope.

💡 Suggested test hardening
-      const filtered = await client.workItems.list(workspaceSlug, projectId, {
-        pql: 'priority IN ("high")',
-      });
+      const filtered = await client.workItems.list(workspaceSlug, projectId, {
+        // Keep the PQL test focused on the created fixture and avoid page-order flakiness.
+        pql: `priority IN ("high") AND name = "${name}"`,
+      });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const filtered = await client.workItems.list(workspaceSlug, projectId, {
pql: 'priority IN ("high")',
});
expect(filtered).toBeDefined();
expect(Array.isArray(filtered.results)).toBe(true);
expect(filtered.results.length).toBeGreaterThan(0);
expect(filtered.results.find((wi) => wi.id === pqlWorkItem!.id)).toBeDefined();
for (const wi of filtered.results) {
const filtered = await client.workItems.list(workspaceSlug, projectId, {
// Keep the PQL test focused on the created fixture and avoid page-order flakiness.
pql: `priority IN ("high") AND name = "${name}"`,
});
expect(filtered).toBeDefined();
expect(Array.isArray(filtered.results)).toBe(true);
expect(filtered.results.length).toBeGreaterThan(0);
expect(filtered.results.find((wi) => wi.id === pqlWorkItem!.id)).toBeDefined();
for (const wi of filtered.results) {
🧰 Tools
🪛 ESLint

[error] 99-99: 'expect' is not defined.

(no-undef)


[error] 100-100: 'expect' is not defined.

(no-undef)


[error] 101-101: 'expect' is not defined.

(no-undef)


[error] 102-102: 'expect' is not defined.

(no-undef)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/work-items/work-items.test.ts` around lines 95 - 103, The PQL test
is non-deterministic because 'priority IN ("high")' can return many items across
pages; change the call to client.workItems.list (used with workspaceSlug,
projectId) to either include a PQL clause that uniquely identifies the created
test item (e.g., add name or id: `priority IN ("high") AND name = "..."` or use
the test-created identifier stored in pqlWorkItem) or set explicit
pagination/sorting so the created item is guaranteed to appear (e.g., request a
sufficiently large page size and sort by created/updated timestamp descending).
Update the test assertions to use that tightened PQL or pagination to reliably
find pqlWorkItem in filtered.results.

Copy link
Copy Markdown
Member

@Saurabhkmr98 Saurabhkmr98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants